home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap08
/
b08d005.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
3KB
|
68 lines
0, In this demonstration, I'll teach you
3, how to add drag-and-drop support to your
5, user interface. The special effect I'll
7, create is a trash-can style burn barrel
9, that you can use to discard unwanted
11, objects on your form. The first step in
14, drag-and-drop is setting the picture
17, DragMode and DragIcon properties for the
21, objects you plan to drag. In this program,
25, these source objects are the CD icon, the
28, gas pump icon, banana icon, and the match
32, icon. Next, I'll continue to configure
37, the target object for the drag-and-drop
39, operation. In this case, the empty burn
42, barrel. Since I want to add a flame
45, effect when I drag in the match, I'll create
48, a second icon that I can copy to the
51, first empty burn barrel location. To hide
54, the fire barrel until the right moment,
57, I've set its Visible property to False.
61, I'll verify that here in the Properties
63, window. There's one last property
65, setting I'd like to mention, and that's the
68, Tag property for the match icon. The Tag
71, property has been set to Fire. And in my
74, event procedure, I'll check each source
76, icon for the Tag property to see if fire
79, has been put into the burn barrel. My
82, point here is that I want to start the
83, fire burning only when the match icon
86, appears. Now, let's look at the program
89, statements that complete the drag-and-drop
91, operation. I'll double-click the target
94, object and open the Code window. And I'll
98, close the Properties window to get a
100, better view. The first line uses the
105, Source variable and the Visible property to
108, hide the object that was dragged and
110, dropped. This makes it look like the item
112, was thrown into the burn barrel. The
115, remaining lines check whether the object
116, thrown away was the match icon. Remember,
120, that I set the Tag property of the Image3
123, object to Fire to identify it as the
127, match that would light the burn barrel. The
130, If...Then decision structure uses Tag
132, Now to check whether the match is being
134, thrown into the barrel. If it is, the
139, decision structure lights the fire by
141, copying the burn barrel icon over the empty
144, barrel icon. Now that we've looked at the
148, program code, let's run the program.
155, When I drag the CD icon toward the burn
156, barrel, I have a drag icon that appears,
159, which in this case is the same as the
161, original CD icon. When I drop it into the
163, burn barrel, the CD icon disappears from
166, the screen. The same happens when I drag
168, the banana icon into the burn barrel
171, and when I drag the gas pump icon into the
173, burn barrel. This should really get the
175, fire going. But when I drag the match
178, icon and release it, boom! Not only does
182, it remove the match icon, but it causes
185, the Image1 swap, and lights the burn
188, barrel. Well, that's it, drag and drop,
191, step by step.
194, END